package com.yunhai.ucenter.controller;

import com.yunhai.common.dto.Ret;
import com.yunhai.model.vo.ums.AccountPasswordVo;
import com.yunhai.model.vo.ums.ResetPasswordVo;
import com.yunhai.model.vo.ums.UserInfoVo;
import com.yunhai.ucenter.service.SysUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RequestMapping("/auth")
@RestController
public class LoginController {

    @Resource
    private SysUserService sysUserService;

    /**
     * 账号密码登录
     * */
    @PostMapping("/username")
    public Ret loginByUsername(@RequestBody AccountPasswordVo accountPasswordVo) throws Exception {

        UserInfoVo userInfoVo = sysUserService.loginByUsername(accountPasswordVo);
        return Ret.ok(userInfoVo);
    }

    /**
     * 重置密码
     * */
    @PostMapping("/pwd/reset")
    public Ret resetPassword(@RequestBody ResetPasswordVo resetPasswordVo) throws Exception {

        sysUserService.resetPassword(resetPasswordVo);
        return Ret.ok();
    }

    /**
     * 获取验证码
     * */
    @GetMapping("/validate/code")
    public Ret getValidateCode( @RequestParam("phoneNumber") String phoneNumber ) throws Exception {

        String validateCode = sysUserService.getValidateCode(phoneNumber);
        return Ret.ok(validateCode);
    }


}
